package com.yanqu.road.server.manger.activity;

import com.yanqu.road.dao.impl.activity.soulbone.SoulBoneLotteryConfigDaoImpl;
import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.soulbone.SoulBoneConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.soulbone.SoulBoneModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;

import java.util.List;
import java.util.Map;

public class SoulBoneActivityMgr extends TempMgr {

    private static SoulBoneConfig config;

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean stop() {
        return true;
    }

    @Override
    public boolean save() {
        return true;
    }

    public static void reloadActivityData() {
        getLogger().info("reload SoulBone Activity start");
        ActivityInfo tempActivityInfo;
        List<ActivityInfo> openActivityInfoList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.SoulBoneLottery.getValue());
        if (openActivityInfoList.isEmpty()) {
            getLogger().info("no SoulBone Activity in show time");
            config = null;
        }else {

            tempActivityInfo = openActivityInfoList.get(0);
            int tmpActivityId = tempActivityInfo.getActivityId();

            SoulBoneConfig configTemp  = new SoulBoneConfig(tempActivityInfo);

            //config配置
            Map<String, ActivityConfig> activityConfigMap = NormalActivityMgr.getActivityConfigMap(tmpActivityId);

            SoulBoneLotteryConfigDaoImpl dao = new SoulBoneLotteryConfigDaoImpl();

            configTemp.setLotteryInfoList(dao.getSoulBoneLotteryInfoList(tmpActivityId));

            configTemp.setMarqueeLimit(activityConfigMap.get("SOUL_BONE_MARQUEE_LIMIT").getIntValue());
            configTemp.setItemId(activityConfigMap.get("SOUL_BONE_ROLL_ITEM_ID").getIntValue());
            configTemp.setConsumeNum(activityConfigMap.get("SOUL_BONE_ROLL_CONSUME").getIntValue());
            configTemp.setGuaranteeNum(activityConfigMap.get("SOUL_BONE_ROLL_GUARANTEE_NUM").getIntValue());
            configTemp.setBigGuaranteeTimes(activityConfigMap.get("SOUL_BONE_ROLL_BIG_GUARANTEE_TIMES").getIntValue());
            configTemp.setGetReward(activityConfigMap.get("SOUL_BONE_ROLL_GET_REWARD").getValue());
            configTemp.setMarqueeStar(activityConfigMap.get("SOUL_BONE_MARQUEE_STAR").getIntValue());

            String soul_bone_roll_guarantee_param = activityConfigMap.get("SOUL_BONE_ROLL_GUARANTEE_PARAM").getValue();
            configTemp.parseGuaranteeParam(soul_bone_roll_guarantee_param);

            String soul_bone_roll_big_guarantee_param = activityConfigMap.get("SOUL_BONE_ROLL_BIG_GUARANTEE_PARAM").getValue();
            configTemp.parseBigGuaranteeParam(soul_bone_roll_big_guarantee_param);

            String soul_bone_roll_type_guarantee_6 = activityConfigMap.get("SOUL_BONE_ROLL_TYPE_GUARANTEE_6").getValue();
            configTemp.parseGuarantee6(soul_bone_roll_type_guarantee_6);

            String soul_bone_roll_type_guarantee_7 = activityConfigMap.get("SOUL_BONE_ROLL_TYPE_GUARANTEE_7").getValue();
            configTemp.parseGuarantee7(soul_bone_roll_type_guarantee_7);

            config = configTemp;

            getLogger().info("find SoulBone Activity {} in show time", tmpActivityId);
        }

        getLogger().info("reload SoulBone Activity finish");

        // 在线玩家下发数据
        for (GamePlayer gamePlayer : GamePlayerMgr.getAllOnlinePlayer()) {
            SoulBoneModule module = gamePlayer.getModule(SoulBoneModule.class);
            module.activityReload();
        }
    }

    public static ActivityInfo getActivityInfo() {
        if(config != null){
            return config.getActivityInfo();
        }
        return null;
    }

    public static SoulBoneConfig getConfig() {
        return config;
    }
}
